import "nprogress/nprogress.css";//加载进度条的css样式
import {start ,done,configure} from "nprogress";
import NotFound from "@/views/404.vue";

/**
 * 
 * @param {Function} start :进度条开始
 * @param {Function} done :进度条结束
 * @param {Function} configure :配置
 * @returns 
 */
 
configure({
    trickleSpeed:20, //速度
    showSpinner:false
})



//延迟
function delay(time){
    return new Promise((resolve)=>{
        setTimeout(()=>{
            resolve();
        },time)
    })
}

/**
 * 异步获取组件
 */
function getPageComponent(pageCompResolve){
    return async ()=>{
        //组件开始加载
        start();

        if(process.env.NODE_ENV=='development'){
            delay(2000);
        }
        const comp = await pageCompResolve();//加载组件

        //组件加载结束
        done();
        return comp;
    }
}


const routes = [
    {
        name: 'home',
        path: '/',
        component: getPageComponent(()=>import('@/views/Home/index.vue')),
        meta:{
            title:'首页'
        }
    },
    {
        name: 'blog',
        path: '/article',
        component: getPageComponent(()=>import('@/views/Blog/index.vue')),
        meta:{
            title:'文章',
        }
    },
    {
        name: "CategoryBlog",
        path: '/article/cate/:categoryId',
        component:getPageComponent( ()=>import('@/views/Blog/index.vue')),
        meta:{
            title:'文章'
        }
    },
    {
        name:'BlogDetail',
        path:'/article/:id',
        component:getPageComponent(()=>import('@/views/Blog/Detail.vue')),
        meta:{
            title:'文章详情'
        }
    },
    {
        name: 'about',
        path: '/about',
        component: getPageComponent(()=>import('@/views/About/index.vue')),
        meta:{
            title:'关于我'
        }
    },
    {
        name: 'project',
        path: '/project',
        component: getPageComponent(()=>import('@/views/Project/index.vue')),
        meta:{
            title:'项目&效果'
        }
    },
    {
        name: 'message',
        path: '/message',
        component:getPageComponent(()=>import('@/views/Message/index.vue')),
        meta:{
            title:'留言板'
        }
    },{
        name:'NotFound',
        path:'*',
        component:NotFound
    }
    
]

export default routes;
